
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>DataSource with Polling</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
</style>

<!--end custom header content for this example-->

</head>

<body class=" yui-skin-sam">

<h1>DataSource with Polling</h1>

<div class="exampleIntro">
	DataSource's Pollable extension enables polling functionality on all your DataSource instances.
			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<form id="demo">
    <h6>Poll every second for current time:</h6>
    <input type="button" id="demo_enable" value="Start polling">
    <input type="button" id="demo_disable" value="End polling">
    <div id="demo_output_polling" class="output"></div>
</form>

<script type="text/javascript">
YUI({base:"../../build/", timeout: 10000}).use("dump", "node", "datasource-function", "datasource-polling", function (Y) {
    var id,
        myFunction = function() {
            return new Date();
        },
        myDataSource = new Y.DataSource.Function({source:myFunction}),
        callback = {
            success: function(e){
                Y.get("#demo_output_polling").setContent("At the tone the time will be: " + Y.dump(e.response.results[0].toString()));
            },
            failure: function(e){
                Y.get("#demo_output_polling").setContent("Could not retrieve data: " + e.error.message);
            }
        };

    Y.on("click", function(e){
        if(id) {
            myDataSource.clearInterval(id);
        }
        id = myDataSource.setInterval(1000, null,callback);
    }, "#demo_enable");
    
    Y.on("click", function(e){
        myDataSource.clearInterval(id);
    }, "#demo_disable");
});
</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
